#{set 'board'}true#{/set}
#{extends 'overlay.html' /} #{set title:'Sprint Backlog' /} 
#{ifnot tasks}
<div id="NOTE"style="padding: 10px 10px 10px 10px" class="ui-state-highlight ui-corner-all"> 
	<span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-info"></span>
	<strong>NOTE: </strong>There isn't enough data to display</div>
#{/ifnot}
#{else}
#{set 'moreStyles'}
<style type="text/css">
thead
{
cursor:move;
}
</style>
#{/set}
#{set 'moreScripts'}
<script language="javascript" type="text/javascript"src="@{'/public/javascripts/jeditable-mod.js'}"></script>
<script  type="text/javascript" src="@{'/public/javascripts/dragtablenorm.js/'}" ></script>
<script  type="text/javascript" src="@{'/public/javascripts/sorttable.js/'}" ></script>
<script type="text/javascript">
function hideOrShow(c)
{
	$('.'+c).toggle();
}
function magicFix(el)
{
	var anId = $(el).closest('select').attr('id');
	$(el).closest('form').hide();
	$(el).closest('td').children().first().html($('#'+anId+' option:selected').text());
	$(el).closest('td').children().first().show();
}
#{if sprint.running()}
#{if connected.in(project).can('editBacklog') || connected.isAdmin}

function changeT (id,id2)
{
	$.post('@{Tasks.edit_task_type()}',{id:id,type_id:id2,user_id:${connected.id}});
}
function changeS (id,id2)
{
	$.post('@{Tasks.edit_task_status()}',{id:id,status_id:id2},function(ret) 
	{
		parent_message_bar(ret);
	});
}
function changeA (id,id2)
{
	$.post('@{Tasks.assign_task_assignee()}',{task_id:id,assignee_id:id2},function(ret) 
	{
		parent_message_bar(ret);
	});
}
function changeR (id,id2)
{
	$.post('@{Tasks.assign_task_reviewer()}',{task_id:id,reviewer_id:id2},function(ret) 
	{
		parent_message_bar(ret);
	});
}
$(function() 
{
	$(".enterEffort").each(function()
	{
		if($(this).html()!='')
			$(this).html(parseInt($(this).html()));
	});

	$(".editPOINTS").each(function()
	{
		if($(this).html()!='')
			$(this).html(parseInt($(this).html()));
	});

    $('.enterEffort').editable(
    function(value)
    {
        var theId 		= $('#lolid').closest("td").attr("id");
        var splitted 	= theId.split("_");
        var taskId 		= parseInt(splitted[0])
        var dayId 		= parseInt(splitted[2])-1;
    	var points 		= parseInt(value);
		var flag = true;
    	$.post('@{Tasks.enter_effort()}',{id:taskId,effort:points,day:dayId},function(ret) 
        {
			parent_message_bar(ret);
			if(ret.indexOf("cannot")!=-1)
				flag=false;
	    });       
	    if(flag)     	
        return(value);      
    },
    {    
        indicator : 'Saving...',
    });

    $('.editDES').editable(
    	    function(value)
    	    {
    	    	var taskId 	= parseInt($('#lolid').closest("tr").attr("id").split("_")[1]);
    	       
    	        $.post('@{Tasks.edit_task_description()}',{id:taskId, user_id:${connected.id},description:value});

        	    return(value);
    	        
    	    },
    	    {    
    	        indicator : 'Saving...',
    	       
    	    });
    
    
    $('.editPOINTS').editable(
    	    function(value)
    	    {
    	    	var theId 		= $('#lolid').closest("td").attr("id");
    	        var splitted 	= theId.split("_");
    	        var taskId 		= parseInt(splitted[0])
    	    	var points 		= parseInt(value);
    	        var flage       = true;
    	    		$.post('@{Tasks.edit_task_points()}',{id:taskId,estimation:points}, function(ret) 
    	    	    {
    	    			parent_message_bar(ret);
    	    			if(ret.indexOf("cannot")!=-1)
							flage = false;
    	    		});
    	    		if(flage)
						return(value);  
    	    	      
    	    },
    	    {    
    	        indicator : 'Saving...',
    	       
    	    });

});
#{/if}
#{else}
$(function() 
		{
			$(".enterEffort").each(function()
			{
				if($(this).html()!='')
					$(this).html(parseInt($(this).html()));
			});

			$(".editPOINTS").each(function()
			{
				if($(this).html()!='')
					$(this).html(parseInt($(this).html()));
			});});
#{/else}
#{/if}
</script>

#{/set}
<div id="sprint">

<h1 style="float:left">#{if component_id==0}Sprint ${sprint_number}: ${project.name}'s Backlog#{/if}#{else}Sprint ${sprint_number}: ${cs}'s Backlog#{/else}</h1>
<div style="position:fixed;right:10px;text-align:right;z-index:2147483647;">
<div class="allCornersRounded" style="background:#333;padding:15px;border-width:10px 10px 0;color:#eee">	
Show/Hide:

		<select id="hideshow"name="list">
        	<option onclick="hideOrShow('shDes');">Description</option> 
        	<option onclick="hideOrShow('shReviewer');">Reviewer</option> 
        	<option onclick="hideOrShow('shAssignee');">Assignee</option> 
        	<option onclick="hideOrShow('shType');">Type</option> 
        	<option onclick="hideOrShow('shStatus');">Status</option> 
        	<option onclick="hideOrShow('shPoints');">Points</option> 
        	<option onclick="hideOrShow('shEfforts');">Efforts</option> 
		</select>

</div>
<div class="notchBottom" style="border-top-color:#333"></div>
</div>
<br style="clear:both"/>
<table id="sprintTable" class="draggable sortable" style="margin-top:40px">
	<thead>
	<tr>
		<td>ID</td>
		<td class="shDes">Description</td>
		<td class="shType">Type</td>
		<td class="shStatus">Status</td>
		<td class="shAssignee">Assignee</td>
		<td class="shReviewer">Reviewer</td>
		<td class="shPoints">Total Points</td>
		#{list items:day_headers, as:'day'}
		<td class="shEfforts">Day ${day}</td>
		#{/list}
	</tr>
	</thead>
	#{list items:tasks, as:'task'}
	<tr name="@{sprintBacklog.index(component_id,id)}"id="task_${task.id}">
	
		<td>
			<a title="view the task reports?" href="@{Tasks.report(task.id)}">${task.getTaskNumber()}</a>
		</td>
		
		#{ifnot connected.in(project).can('editBacklog') || connected.isAdmin || (connected==task.assignee) || connected==task.reviewer || sprint.running()}
          #{ifnot task.description}
          <td id="${task.id}_des"class="shDes">No Description stated</td>
          #{/ifnot}
          #{else}
		<td id="${task.id}_des"class="shDes">${task.description}</td>
          #{/else}
          
          #{ifnot task.taskType}
          <td id="${task.id}_type"class="shType">No Type stated</td>
          #{/ifnot}
          #{else}
          <td id="${task.id}_type"class="shType">${task.taskType.name}</td>
          #{/else}
          
           #{ifnot task.taskStatus}
          <td id="${task.id}_status"class="shStatus">No Status stated</td>
          #{/ifnot}
          #{else}
          <td id="${task.id}_status"class="shStatus">${task.taskStatus.name}</td>
          #{/else}
        
          #{ifnot task.assignee}
          <td id="${task.id}_assignee"class="shAssignee">No assignee stated</td>
          #{/ifnot}
          #{else}
          <td id="${task.id}_assignee"class="shAssignee">${task.assignee.name}</td>
          #{/else}
        
         #{ifnot task.reviewer}
          <td id="${task.id}_reviewer"class="shReviewer">No reviewer stated</td>
          #{/ifnot}
          #{else}
          <td id="${task.id}_reviewer"class="shReviewer">${task.reviewer.name}</td>
          #{/else}
        
         #{ifnot task.estimationPoints}
          <td id="${task.id}_points"class="shPoints">0</td>
          #{/ifnot}
          #{else}
          <td id="${task.id}_points"class="shPoints">${task.estimationPoints}</td>
          #{/else}
        
        <!--@author Hadeer Younis C4 S8-->
        #{list items:day_headers, as:'day'}
		<td class="shEfforts"style="text-align: center" id="${task.id}_day_${day}" >
		#{if task.getEffortPerDay(day-1)==-1.0}&nbsp;
		#{/if} #{else} ${task.getEffortPerDay(day-1)} #{/else}</td>
		#{/list}
	
        
        #{/ifnot}
      
            
      
        #{else}
		#{ifnot task.description}
		<td class="shDes" id="${task.id}_des"><span id="${task.id}" class="editDES">No description stated
		</span></td>
		#{/ifnot} #{else}
		<td class="editDES shDes" title="edit the description?" id="${task.id}">${task.description}</td>
		#{/else} 
		
		<td id="${task.id}_type" class="editTYPE shType">
			#{if connected.in(project).can('changeTaskType')|| connected==task.assignee}
					#{ifnot task.taskType}
	    <span  #{if sprint.running()}onclick="$(this).next().show();$(this).hide()"#{/if}>---</span>
	    #{/ifnot}
	    #{else}
	    <span  #{if sprint.running()}onclick="$(this).next().show();$(this).hide()"#{/if}>${task.taskType.name}</span>
	    #{/else}
	     #{if sprint.running()}
		<form style="display:none">
			
			<select id="t_${task.id}_t"onblur="magicFix(this)" onchange="magicFix(this);changeT(${task.id},parseInt($('#t_${task.id}_t option:selected').val()));">
       		#{ifnot task.taskType.name}
       			<option value="${type.id}">---</option>
       		#{/ifnot}
       		#{list items:types, as:'type'}
       		#{if task.taskType}
       			#{if type.name==task.taskType.name}
       				<option selected="selected" value="${type.id}">${type.name}</option>
       			#{/if}
       			#{else}
       				<option value="${type.id}">${type.name}</option>	
       			#{/else}
       		#{/if}
       		#{else}
       			<option value="${type.id}">${type.name}</option>
       		#{/else}
       		#{/list}
			</select>
		</form> #{/if}
	    #{/if}
	    #{else}
	    #{ifnot task.taskType}
	    ---
	    #{/ifnot}
	    #{else}
	    ${task.taskType.name}
	    #{/else}
	    #{/else}
</td>

		<td id="${task.id}_status" class="editStatus shStatus">
		#{if connected.in(project).can('changeTaskStatus') ||connected==task.reviewer || connected==task.assignee}
		#{ifnot task.taskStatus}
	    <span  #{if sprint.running()}onclick="$(this).next().show();$(this).hide()"#{/if}>---</span>
	    #{/ifnot}
	    #{else}
	    <span  #{if sprint.running()}onclick="$(this).next().show();$(this).hide()"#{/if}>${task.taskStatus.name}</span>
	    #{/else} #{if sprint.running()}
		<form style="display:none">
			<select id="t_${task.id}_s"onblur="magicFix(this)" onchange="magicFix(this);changeS(${task.id},parseInt($('#t_${task.id}_s option:selected').val()));">
       		#{ifnot task.taskStatus.name}
       			<option value="${type.id}">---</option>
       		#{/ifnot}
       		#{list items:statuses, as:'type'}
       		#{if task.taskStatus}
       			#{if type.name==task.taskStatus.name}
       				<option selected="selected" value="${type.id}">${type.name}</option>
       			#{/if}
       			#{else}
       				<option value="${type.id}">${type.name}</option>	
       			#{/else}
       		#{/if}
       		#{else}
       			<option value="${type.id}">${type.name}</option>
       		#{/else}
       		#{/list}
			</select>
		</form> #{/if}
	    #{/if}
	    #{else}
	    #{ifnot task.taskType}
	    ---
	    #{/ifnot}
	    #{else}
	    ${task.taskType.name}
	    #{/else}
	    #{/else}
		</td>

		
		
		<td id="${task.id}_assignee" class="editASSI shAssignee">
			#{if connected.in(project).can('changeTaskAssignee') || connected==task.assignee}
		#{ifnot task.assignee}
	    <span  #{if sprint.running()}onclick="$(this).next().show();$(this).hide()"#{/if}>---</span>
	    #{/ifnot}
	    #{else}
	    <span  #{if sprint.running()} onclick="$(this).next().show();$(this).hide()"#{/if}>${task.assignee.getDisplayName().raw()}</span>
	    #{/else} #{if sprint.running()}
		<form style="display:none">
			<select id="t_${task.id}_a"onblur="magicFix(this)" onchange="magicFix(this);changeA(${task.id},parseInt($('#t_${task.id}_a option:selected').val()));">
       		#{ifnot task.assignee}
       			<option value="${type.id}">---</option>
       		#{/ifnot}
       		#{list items:task.getAssigneeOrReviewer(true), as:'type'}
       		#{if task.assignee}
       			#{if type==task.assignee}
       				<option selected="selected" value="${type.id}">${type.getDisplayName().raw()}</option>
       			#{/if}
       			#{else}
       				<option value="${type.id}">${type.getDisplayName().raw()}</option>	
       			#{/else}
       		#{/if}
       		#{else}
       			<option value="${type.id}">${type.getDisplayName().raw()}</option>
       		#{/else}
       		#{/list}
			</select>
		</form> #{/if}
	    #{/if}
	    #{else}
	    #{ifnot task.assignee}
	    ---
	    #{/ifnot}
	    #{else}
	    ${task.assignee.getDisplayName().raw()}
	    #{/else}
	    #{/else}

		</td>
		<td id="${task.id}_reviewer" class="editREV shReviewer">
					#{if connected.in(project).can('changeTaskReviewer') || connected==task.assignee}
		#{ifnot task.reviewer}
	    <span  #{if sprint.running()}onclick="$(this).next().show();$(this).hide()"#{/if}>---</span>
	    #{/ifnot}
	    #{else}
	    <span  #{if sprint.running()}onclick="$(this).next().show();$(this).hide();$(this).hide()"#{/if}>${task.reviewer.getDisplayName().raw()}</span>
	    #{/else} #{if sprint.running()}
		<form style="display:none">
			<select id="t_${task.id}_r"onblur="magicFix(this)" onchange="magicFix(this);changeR(${task.id},parseInt($('#t_${task.id}_r option:selected').val()));">
       		#{ifnot task.reviewer}
       			<option>---</option>
       		#{/ifnot}
       		#{list items:task.getAssigneeOrReviewer(false), as:'type'}
       		#{if task.reviewer}
       			#{if type==task.reviewer}
       				<option selected="selected" value="${type.id}">${type.getDisplayName().raw()}</option>
       			#{/if}
       			#{else}
       				<option value="${type.id}">${type.getDisplayName().raw()}</option>	
       			#{/else}
       		#{/if}
       		#{else}
       			<option value="${type.id}">${type.getDisplayName().raw()}</option>
       		#{/else}
       		#{/list}
			</select>
		</form> #{/if}
	    #{/if}
	    #{else}
	    #{ifnot task.reviewer}
	    ---
	    #{/ifnot}
	    #{else}
	    ${task.reviewer.getDisplayName().raw()}
	    #{/else}
	    #{/else}
		</td>
 
		
		#{ifnot task.estimationPoints}
		<td id="${task.id}_points" class="editPOINTS shPoints">0
		</td>
		#{/ifnot}
		 #{else}
		<td id="${task.id}_points" title="edit the estimationpoints?"
			class="editPOINTS shPoints" style="text-align: center">${task.estimationPoints}</td>
		#{/else}
#{ifnot task.subTasks}
		<!--@author Hadeer Younis C4 S8-->
		#{list items:day_headers, as:'day'}
		<td style="text-align: center"id="${task.id}_day_${day}" class="enterEffort shEfforts">
		#{if task.getEffortPerDay(day-1)==-1.0}&nbsp;
		#{/if} #{else} ${task.getEffortPerDay(day-1)} #{/else}</td>
		#{/list}
		#{/ifnot}
		#{/else}
		
	</tr>

	#{/list}
</table>
</div>
#{/else}